#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main()
{
    int x = 0;
    int n = 0;
    while (scanf("%d %d", &x, &n) != EOF)
    {
        if (n > 7)
        {
            x = n % 7 + x;
        }
        else
        {
            x = n + x;
        }
        if (x > 7)
        {
            x = x - 7;
        }
        printf("%d\n", x);
    };

    return 0;
}